
package managedbean.CRM.Customer;

import entity.CRM.LineItem;
import entity.CRM.SaleQuotation;
import entity.CRM.Customer;
import entity.Employee;
import java.lang.Long;
import java.util.List;
import javax.ejb.EJB;
import javax.el.ELContext;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import managedbean.Controller;
import session.stateless.CRM.SaleQuotationBeanLocal;


@ManagedBean(name="viewCustomersQuotations")
@ViewScoped
public class ViewCustomersQuotationsManagerBean {

    public ViewCustomersQuotationsManagerBean() {
    }
    
    @EJB
    private SaleQuotationBeanLocal saleQuotationBeanLocal;
    private Customer selectedCustomer;
    private List<SaleQuotation> selectedSaleQuotations;
    private List<LineItem> lineItems;
    private String statusMessage;
    
    public void initView(PhaseEvent event)
    {
        selectedCustomer = (Customer)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("selectedCustomer");            
        selectedSaleQuotations = saleQuotationBeanLocal.getSaleQuotationByCustomer(selectedCustomer.getRegistrationNumber());
    }

    public Customer getSelectedCustomer() {
        return selectedCustomer;
    }

    public void setSelectedCustomer(Customer selectedCustomer) {
        this.selectedCustomer = selectedCustomer;
    }

    public SaleQuotationBeanLocal getSaleQuotationBeanLocal() {
        return saleQuotationBeanLocal;
    }

    public void setSaleQuotationBeanLocal(SaleQuotationBeanLocal saleQuotationBeanLocal) {
        this.saleQuotationBeanLocal = saleQuotationBeanLocal;
    }

    public List<SaleQuotation> getSelectedSaleQuotations() {
        return selectedSaleQuotations;
    }

    public void setSelectedSaleQuotations(List<SaleQuotation> selectedSaleQuotations) {
        this.selectedSaleQuotations = selectedSaleQuotations;
    }

    public String getStatusMessage() {
        return statusMessage;
    }

    public void setStatusMessage(String statusMessage) {
        this.statusMessage = statusMessage;
    }

    public List<LineItem> getLineItems() {
        return lineItems;
    }

    public void setLineItems(List<LineItem> lineItems) {
        this.lineItems = lineItems;
    }
    
    public List<SaleQuotation> getSaleQuotation(){
        ELContext elContext = FacesContext.getCurrentInstance().getELContext();
        Controller controller = (Controller) FacesContext.getCurrentInstance().getApplication().getELResolver().getValue(elContext, null, "controller");
        Employee executive = controller.getEmployee();
        return saleQuotationBeanLocal.getSaleQuotation(executive.getEmployeeId());
    }

}